import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProContractVO, ProContractForm, ProContractQuery, ConReceiveStatisticVO, ItemTreeNode } from '@/api/project/init/contract/types';


/**
 * 查询合同信息列表
 * @param query
 * @returns {*}
 */

export const listProContract = (query?: ProContractQuery): AxiosPromise<ProContractVO[]> => {
  return request({
    url: '/pro/contract/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询项目信息编辑查询合同列表
 * @param query
 * @returns {*}
 */
export const listProContractForInfo = (query?: ProContractQuery): AxiosPromise<ProContractVO[]> => {
  return request({
    url: '/pro/contract/info/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询项目审核需要显示的合同信息列表
 * 只返回审核状态为：已提交(1)、审核中(2)、审核通过(3)、审核不过(4)的项目
 * @param query
 * @returns {*}
 */
export const getInfoAuditList = (query?: ProContractQuery): AxiosPromise<ProContractVO[]> => {
  return request({
    url: '/pro/contract/infoAudit/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询合同信息详细
 * @param id
 */
export const getProContract = (id: string | number): AxiosPromise<ProContractVO> => {
  return request({
    url: '/pro/contract/' + id,
    method: 'get'
  });
};

/**
 * 新增合同信息
 * @param data 合同信息
 */
export const addProContract = (data: ProContractForm) => {
  return request({
    url: '/pro/contract',
    method: 'post',
    data: data
  });
};

/**
 * 修改合同信息
 * @param data 合同信息
 */
export const updateProContract = (data: ProContractForm) => {
  return request({
    url: '/pro/contract',
    method: 'put',
    data: data
  });
};

/**
 * 删除合同信息
 * @param id
 */
export const delProContract = (id: string | number | Array<string | number>) => {
  return request({
    url: '/pro/contract/' + id,
    method: 'delete'
  });
};

/**
 * 查询合同回款统计列表
 * @param query
 * @returns {*}
 */
export const listConReceiveStatistic = (query?: ProContractQuery): AxiosPromise<ConReceiveStatisticVO[]> => {
  return request({
    url: '/pro/contract/receive/statistic',
    method: 'get',
    params: query
  });
};

/**
 * 重置合同审核流程
 * @param id 合同ID
 */
export const revertContractAuditFlow = (id: string | number) => {
  return request({
    url: '/pro/contract/revert/' + id,
    method: 'get'
  });
};

/**
 * 查询合同日志信息列表
 * @param query
 * @returns {*}
 */
export const logListProContract = (query?: ProContractQuery): AxiosPromise<ProContractVO[]> => {
  return request({
    url: '/pro/contract/logList',
    method: 'get',
    params: query
  });
};

/**
 * 根据合同ID查询合同下所有收款负责人
 * @param contractId 合同ID
 * @returns 收款负责人姓名列表
 */
export const getReceiveLeadersByContractId = (contractId: string | number): AxiosPromise<string> => {
  return request({
    url: '/pro/contract/receiveLeaders/' + contractId,
    method: 'get'
  });
};
